<script setup>
import { userStore as useUserStore } from '@/pinia/user.js'
import moment from 'moment'
const userStore = useUserStore()
const { profile } = storeToRefs(userStore)

const time = ref(moment().format('YYYY-MM-DD HH:mm:ss'))

const timer = setInterval(() => {
  time.value = moment().format('YYYY-MM-DD HH:mm:ss')
}, 1000)

const props = defineProps({
  title: {
    type: String,
    default: ''
  }
})

onMounted(() => {
  console.log(profile.value)
})
onUnmounted(() => {
  clearInterval(timer)
})
</script>

<template>
  <div class="ps-chart-header">
    <div class="time">
      <div class="time-content">
        <div style="color: #fff; font-size: 12px; text-align: center;">正航软件&企管家</div>
        <div class="text">
          {{ time }}
        </div>
      </div>
    </div>

    <div></div>

    <div class="title">
      <span>{{ props.title || profile.company }}</span>
    </div>
    <div class="notification">
      <div class="notification-content">
        <dv-button border="Border6" color="#1f75a8">
          <div class="notification-wrapper">
            <span class="notification-text">{{ profile.dealerNotification }}</span>
            <span class="notification-text">{{ profile.dealerNotification }}</span>
          </div>
        </dv-button>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
@font-face {
  font-family: 'UnidreamLED';
  src: url(../assets/font/DS-Digital/DS-DIGI-1.ttf); /***兼容ie9***/
}
.ps-chart-header {
  width: 100%;
  height: 100%;
  background: url('../assets/image/chart-head2.png') no-repeat;
  background-size: cover;
  background-position: center -40px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  min-width: 0;

  .time {
    min-width: 0;

    display: flex;
    align-items: end;
    justify-content: start;

    font-size: 32px;
    color: #0e94ea;
    position: absolute;
    top: 45px;
    font-weight: bold;
    .text {
      font-family: 'UnidreamLED';
    }
  }

  .title {
    min-width: 0;

    color: #fff;
    font-size: 32px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .notification {
    min-width: 0;

    display: flex;
    align-items: end;
    justify-content: end;
    position: relative;

    .notification-content {
      width: 60%;
      overflow: hidden;
      bottom: 10px;
    }

    .notification-wrapper {
      display: flex; // 确保两个文本块水平排列
      white-space: nowrap; // 防止文本换行
      animation: seamlessLoop 5s linear infinite; // 无缝循环动画
    }

    .notification-text {
      color: #fff;
      margin-right: 20px; // 文本块之间的间距
    }
  }
}
@keyframes seamlessLoop {
  0% {
    transform: translateX(0); // 初始位置
  }
  100% {
    transform: translateX(-50%); // 移动到一半的位置
  }
}
</style>
